package com.ellricky.excute_president.ui.activity.school

import android.os.Bundle
import android.view.View
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.widget.refresh.RefreshFlag
import com.ellricky.baselib.http.callback.EListCallback
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.excute_president.AchieveAdapter
import com.ellricky.excute_president.AchieveEntity

class AchieveFragment : BaseRefreshFragment<Void, BasePresenter<Void>, AchieveEntity>() {


    private lateinit var urlPath: String

    companion object {
        fun newInstance(urlPath: String): AchieveFragment {
            val fragment = AchieveFragment()
            val bundle = Bundle()
            bundle.putString("urlPath", urlPath)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initUIView(view: View?) {
        super.initUIView(view)
        hideToolBar()
        urlPath = arguments?.getString("urlPath") ?: ""
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<AchieveEntity> {
        return AchieveAdapter(mContext)
    }

    override fun getResponseCallback(): BaseCallback {
        return object : EListCallback<AchieveEntity>(mContext) {
            override fun onSuccess(data: MutableList<AchieveEntity>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }

            override fun onErrorCode(code: String?, msg: String?) {
                super.onErrorCode(code, msg)
                rvView.onRefreshFailed(refresh)
            }

            override fun onHttpError(code: String?, msg: String?) {
                super.onHttpError(code, msg)
                rvView.onRefreshFailed(refresh)
            }
        }
    }

    override fun getUrlPath(): String {
        return urlPath
    }

    override fun initParamMap() {

    }

    override fun setRefreshListener() {
        rvView.init(this,RefreshFlag.NONE)
    }
}
